<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2025/7/12
 * Time: 16:01
 */

namespace app\controller\api;
use app\model\Attr;
use app\model\Goods AS model;

use app\controller\Base;

class Goods extends Base
{
    public function list(){
        $where = [];
        $post = input('post.');
        if(!empty($post['nav_id'])){
            $son = Nav::where('pid',$post['nav_id'])->select()->toArray();
            $ids = array_column($son,'id');
            $all = $ids;
            while (count($son) > 0){
                $son = Nav::where('pid','IN',$ids)->select()->toArray();
                $ids = array_column($son,'id');
                $all = array_merge($all,$ids);
            }
            $where[] = ['nav_id','IN',$all];
        }
        $list = model::where($where)
            ->order('create_time DESC')
            ->select();
        return $this->msg($list);
    }

    public function info($id){
        $info = model::find($id);
        return $this->msg($info);
    }

    public function attrdata(){
        $data = input('data');
        foreach ($data AS $key => $value) $ids[] = $value['id'];
        $data = Attr::with(['goods'])->where('id','IN',$ids ?? [0])->select();
        return $this->msg($data);
    }
}